<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 

$iCol = 1;
if( !isset( $categories_per_row )) {
    $categories_per_row = 4;
}
$cellwidth = intval( 100 / $categories_per_row );

if( empty( $categories )) {
    return; // Do nothing, if there are no child categories!
}
?>
<br/>
<table width="100%" cellspacing="0" cellpadding="0" id="list-category-home">
<?php
$category_url = JRequest::getVar('home_category_id');
if($category_url == '' || $category_url == null) {
  $category_url = 15;
}
$active = '';
foreach( $categories as $category ) {
    if ($iCol == 1) { // this is an indicator wether a row needs to be opened or not
        echo "<tr>\n";
    }
    if ($category_url == $category["category_id"]) {
      $active = '_active';
    } else {
      $active = '';
    }
    ?>
    <td align="center" width="<?php echo $cellwidth ?>%" id="<?php echo 'list-category-home_'.$category["category_id"].$active; ?>">
         <a class="category" title="<?php echo $category["category_name"] ?>" href="index.php?home_category_id=<?php echo $category["category_id"]; ?>"> 
            <?php
            echo $category["category_name"];
            echo $category['number_of_products'];
            ?>
         </a><br/>
    </td>
    
    
    <?php
    // Do we need to close the current row now?
    if ($iCol == $categories_per_row) { // If the number of products per row has been reached
        echo "</tr>\n";
        $iCol = 1;
    }
    else {
        $iCol++;
    }
}
// Do we need a final closing row tag?
if (sizeof( $categories ) < $categories_per_row) {
    echo "</tr>\n";
}
?>
</table>